package jsc.gui.util;

public class Vector {

	private double r;
	private double i;

	public Vector(double x, double y) {
		this.r = x;
		this.i = y;
	}

	public Vector add(Vector b) {
		return (new Vector(this.r + b.r, this.i + b.i));
	}

	public Vector sub(Vector b) {
		return (new Vector(this.r - b.r, this.i - b.i));
	}

	public Vector prod(Vector a) {
		return (new Vector(this.r * a.r - this.i * a.i, this.r * a.i + this.i * a.r));
	}
	
	public Vector div(Vector b) {
		return this.prod(b.invConj()).prod(1/(b.r*b.r + b.i*b.i));
	}
	
	public Vector prod(double s) {
		return (new Vector(this.r * s, this.i * s));
	}
	
	public double mod() {
		return Math.sqrt(r()*r() + i()*i());
	}



	public Vector invConj() {
		return (new Vector(this.r, -this.i));
	}
	
	public String toString() {
		return r + ((i > 0)? " + " : " - ") + Math.abs(i);
	}
	
	public double r() {
		return this.r;
	}
	
	public double i() {
		return this.i;
	}
	
	
	


}
